/**
 * @param {string} s
 * @return {number}
 */
var romanToInt = function(s) {
  const LM = {
    'I': 1,'V': 5,'X': 10,'L': 50,'C': 100,'D': 500,'M': 1000,
  }
  let sum = LM[s[s.length -1]];
  for (let i = 0; i < s.length -1; i++) {
    ((LM[s[i]] < LM[s[i + 1]])) ? sum -= LM[s[i]] : sum += LM[s[i]];
  }
  return sum;
};

console.log(romanToInt('IV'));